package org.flexthinker.binding.ui.form.binding.support
{
    import org.flexthinker.binding.form.support.DefaultValidatingFormModel;
    import org.flexthinker.binding.ui.form.binding.Binder;
    import org.flexthinker.binding.value.support.MockBean;
    import org.hamcrest.assertThat;
    import org.hamcrest.core.throws;
    import org.hamcrest.object.instanceOf;

    import spark.components.Label;

    public class AbstractBinderTest
    {
        private var label:Label;
        private var bean:MockBean;

        public function AbstractBinderTest()
        {
        }

        [Before]
        public function setUp():void
        {
            this.label = new Label();
            bean = new MockBean();
        }

        [Test]
        public function testInitialization():void
        {
            var b:Binder = new AbstractBinder(label, "simpleString");
            assertThat(
                    function():void
                    {
                        b = new AbstractBinder(label, null);
                    },
            throws(instanceOf(ArgumentError)));

            assertThat(
                    function():void
                    {
                        b = new AbstractBinder(null, "simpleString");
                    },
            throws(instanceOf(ArgumentError)));
        }

        [Test]
        public function testCreateBindingThrowsError():void
        {
            var b:Binder = new AbstractBinder(label, "simpleString");
            assertThat(
                    function():void
                    {
                        b.getBinding(new DefaultValidatingFormModel(bean))
                    },
            throws(instanceOf(Error)));
        }

    }
}
